package com.shujia.day18;

import java.io.*;
import java.util.ArrayList;

public class Home3ReadCodeLine {
    public static void main(String[] args) throws IOException {

        File file = new File("src/com/shujia");

//        Integer num = new Integer(0);
//        int fileNum = 0;
//        Integer fileNum = new Integer(0);
        ArrayList<Integer> nums = new ArrayList<>();
        readCodeLine(file,nums);

        int num = 0;
        for (Integer oneNum : nums) {
            num += oneNum;
        }
        System.out.println("一共敲了："+num+"行代码");
        System.out.println("一共敲了："+nums.size()+"个代码文件");


    }

    public static void readCodeLine(File file,ArrayList<Integer> nums) throws IOException {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File nextFile : files) {
                readCodeLine(nextFile,nums);
            }
        }else {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
            String line = "";
            int oneFileNum = 0;
            while( (line = bufferedReader.readLine()) != null){
                String replace = line.replace(" ", "");
                if (replace.length() > 2){
                    oneFileNum += 1;
                }
            }
            nums.add(oneFileNum);
            bufferedReader.close();
        }

    }
}
